import Vue from 'vue'
import Vuex from 'vuex'

import {
  tbSysUserQuery,
  tbUserDelete,
  tbUserBatchBanAndRecovery,
  tbSysUserBatchUpdatePassword,
  tbUserAddBatch,
  tbUserBatchUpdateDept,
  tbUserQueryOne,
  tbUserAdd,
  tbUserUpdate,
  tbUserVali,
  tbUserImport,
  tbUserUpdateDiskSize,
} from '@/api/admin/user/tbSysUser'

Vue.use(Vuex)

const state = {
  checkedUser: [],
}

const getters = {}

const actions = {
  async queryTbUserList({ commit }, listQuery) {
    let res = await tbSysUserQuery({ ...listQuery })
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async queryTbUserById({ commit }, userId) {
    let res = await tbUserQueryOne(userId)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async deleteTbUser({ commit }, list) {
    let res = await tbUserDelete(list)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //封禁|激活用户
  async banAndRecoveryTbUserBatch({ commit }, list) {
    let res = await tbUserBatchBanAndRecovery(list)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //重置密码
  async resetPasswordTbUser({ commit }, list) {
    let res = await tbSysUserBatchUpdatePassword(list)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //批量设置角色
  async addBatchTbUser({ commit }, list) {
    let res = await tbUserAddBatch(list)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  //批量设置部门
  async addDeptBatchTbUser({ commit }, list) {
    let res = await tbUserBatchUpdateDept(list)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async addTbUser({ commit }, data) {
    let res = await tbUserAdd(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async updateTbUser({ commit }, data) {
    let res = await tbUserUpdate(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
  async verifyTbUser({ commit }, data) {
    let res = await tbUserVali(data)
    return res.data.code == 0 ? res.data : Promise.reject(new Error('faile'))
  },
}

const mutations = {
  SET_USER: (state, d) => {
    state.checkedUser = d
  },
}

export default {
  state,
  getters,
  actions,
  mutations,
}
